//
//  File.m
//  MandalaChart
//
//  Created by Ignacio Enriquez Gutierrez on 8/9/10.
//  Copyright (c) 2010 Nacho4D.
//  See the file license.txt for copying permission.
//

#import "treeNode.h"
#import "SourceListItem.h"

@implementation treeNode
@synthesize name, parent_path_SourceListItem;
@synthesize expanded;
@synthesize level;
@synthesize self_path_SourceListItem;
@synthesize parentkey;

//Lazy properties:
 
- (UIImage *) image{
	if (!image) {
		if ([self isDirectory]) 
			image = [UIImage imageNamed:@"Folder56.png"];
		else
			image = [UIImage imageNamed:@"Document56.png"];		
	}
	return image;
}
- (UIImage *) imageBig{
	if (!imageBig) {
		if ([self isDirectory]) 
			imageBig = [UIImage imageNamed:@"Folder512.png"];
		else
			imageBig = [UIImage imageNamed:@"Document512.png"];		
	}
	return imageBig;
	
}
 

 

- (BOOL) isDirectory{
    //NSLog(@"判斷 isDirectory %@ %@",name,parentDirectory);
           
    
    //NSLog(@"si title=%@ %@",[si title],[si isUseForGroup ] );
    
    if ([[self_path_SourceListItem isUseForGroup ]isEqualToNumber:[NSNumber numberWithBool:YES]]){
         
        return YES;
    }    
    else {
        
        return NO;
    }
         
    
}

 



- (NSString *) description{
	return [NSString stringWithFormat:@"treeNode:%@ directory:%@",  [self name], (self.isDirectory)?@"YES": @"NO"];
}
 
#pragma mark -

 

- (void) unloadMembers{
	//TODO: release members and set them to nil
}

- (id) initWithName:(NSString *)aName parentDirectory:(SourceListItem *)aParentDirectory selfDirectory:(SourceListItem *)aSelfDirectory datamodel:(Data_Model *)dm parentkey:(treeNode *)pkey{
	if (self = [super init]) {
		
        self.name = aName;
		self.parent_path_SourceListItem = aParentDirectory;
		self.self_path_SourceListItem=aSelfDirectory;
        self.parentkey=pkey;
        
		 
		 
		image = nil;
		imageBig = nil;
		 
		
        datamodel_n4file=[dm retain];
        
	}
	return self;
}

- (id) init{
	return [self initWithName:@"" parentDirectory:nil selfDirectory:nil  datamodel:nil parentkey:nil];
}

- (void) dealloc{
    [datamodel_n4file release];
	[name release];
	[parent_path_SourceListItem release];
    [self_path_SourceListItem release];
	[super dealloc];
}

#pragma mark -
#pragma mark NSCopying

- (id)copyWithZone:(NSZone *)zone{
	//Shallow copy : We need a shallow copies here since instances of treeNode class 
	//will become keys in NSDictionaries as well and comparing pointers is easier much easier.
	return [self retain];
}

@end
